<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">昵称</label>
        <div class="layui-input-block">
            <input type="text" name="nickname" lay-verify="required" lay-reqtext="昵称不能为空" placeholder="请输入昵称" value="" class="layui-input">
            <tip>填写自己账号的昵称。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">帐号</label>
        <div class="layui-input-block">
            <input type="text" name="username" lay-verify="required" lay-reqtext="帐号不能为空" placeholder="请输入帐号" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">密码</label>
        <div class="layui-input-block">
            <input type="password" name="password" lay-verify="required" lay-reqtext="密码不能为空" placeholder="请输入密码" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认</button>
        </div>
    </div>
</div>

<!--<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>-->
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            roleType = layui.data("user").roleType,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                type: "POST",
                url: "/zxjy/user/add/"+roleType.toLowerCase(),
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(data.field),
                headers: {
                    'Authorization': layui.data("Authorization")['Authorization'],
                },
                success: function (result) {
                    layer.alert(JSON.stringify(result.message))
                    if (result.state === 200) {
                        parent.layui.table.reload("currentTableId");
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    }
                }
            });

            // $.post("/zxjy/user/add/supervisor", data.field, function (result) {
            //     if (result.state !== 200) {
            //         layer.alert(result.message);
            //     }
            // });
        });



        // var index = layer.alert(JSON.stringify(data.field), {
        //     title: '最终的提交信息'
        // }, function () {
        //     $.post("/zxjy/user/add/supervisor", data.field,function(result){
        //         if (result.state !== 200){
        //             layer.alert(result.message);
        //         }
        //     });
        //
        //     // 关闭弹出层
        //     layer.close(index);

        //         var iframeIndex = parent.layer.getFrameIndex(window.name);
        //         parent.layer.close(iframeIndex);
        //
        //     });
        //
        //     return false;
        // });

    });
</script>
</body>
</html>
